package com.docmgmt.mvp.controller;

import com.docmgmt.mvp.dto.Result;
import com.docmgmt.mvp.ragflow.RAGFlowClient;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 健康检查控制器
 */
@RestController
@RequestMapping("/health")
@RequiredArgsConstructor
public class HealthController {

    private final RAGFlowClient ragFlowClient;

    /**
     * 健康检查
     *
     * GET /api/health
     */
    @GetMapping
    public Result<Map<String, Object>> healthCheck() {
        Map<String, Object> status = new HashMap<>();

        // 检查后端服务
        status.put("backend", "healthy");

        // 检查 RAGFlow 连接
        boolean ragflowConnected = ragFlowClient.testConnection();
        status.put("ragflow", ragflowConnected ? "connected" : "disconnected");

        return Result.success(status);
    }
}
